package com.tvunetworks.center.device.controller;

import com.tvunetworks.center.common.model.LoginUser;
import com.tvunetworks.center.common.util.Result;
import com.tvunetworks.center.common.util.ResultUtil;
import com.tvunetworks.center.device.annotation.Logined;
import com.tvunetworks.center.device.model.param.CustomizedShareParam;
import com.tvunetworks.center.device.model.vo.CustomizedShareVo;
import com.tvunetworks.center.device.service.CustomizedShareService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @program: tvucc-aggregator
 * @description: CustomizedShareController
 * @author lebronchen
 * @create: 2020-03-19 10:40
 **/
@RestController
@RequestMapping("/share")
@Slf4j
public class CustomizedShareController {

    @Autowired
    private CustomizedShareService customizedShareService;

    /**
     * 开始分享
     * @param loginUser loginUser
     * @param param param
     * @return success
     */
    @PostMapping("/start")
    public Result startShare(@Logined LoginUser loginUser, @RequestBody @Valid CustomizedShareParam param){
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        customizedShareService.startShare(loginUser.getId(), param.getRid(), param.getShareId());
        return ResultUtil.success();
    }

    /**
     * 停止
     * @param loginUser loginUser
     * @param param param
     * @return success
     */
    @PostMapping("/stop")
    public Result stopShare(@Logined LoginUser loginUser, @RequestBody @Valid CustomizedShareParam param){
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        customizedShareService.stopShare(loginUser.getId(), param.getRid(), param.getShareId());
        return ResultUtil.success();
    }

    /**
     * 分享数量
     * @param loginUser loginUser
     * @param param param
     * @return success
     */
    @PostMapping("/listShareAccount")
    public Result listShareAccount(@Logined LoginUser loginUser, @RequestBody CustomizedShareParam param){
        if (loginUser == null) {
            return ResultUtil.noLogin();
        }
        List<CustomizedShareVo> list = customizedShareService.listShareAccount(loginUser.getId(), param);
        return ResultUtil.success(list);
    }
}
